package cn.ybk.basic.service.impl;

import cn.ybk.basic.mapper.BaseMapper;
import cn.ybk.basic.query.BaseQuery;
import cn.ybk.basic.service.BaseService;
import cn.ybk.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;


public class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public PageList<T> queryByPage(BaseQuery query) {
        Integer totals = baseMapper.queryByCount(query);
        if (totals <= 0) {
            return new PageList<>(0, new ArrayList<>());
        }
        List<T> rows = baseMapper.queryByPage(query);
        return new PageList<>(totals, rows);

    }

    @Override
    public void batch(List<Long> ids) {
        baseMapper.batch(ids);
    }
}
